﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using FileConvertPdfSystemBLL;
using FileConvertPdfSystemModel;

namespace File_ConvertPdfSystemWinFormTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoginUserConvertpdfQueueBLL ConpdfQueueBLL = new LoginUserConvertpdfQueueBLL();
            DataSet ds = ConpdfQueueBLL.Get_File();
            string username = ds.Tables[0].Rows[0][1].ToString();
            string Filename = ds.Tables[0].Rows[0][3].ToString();
            int num = ds.Tables[0].Rows.Count;
            label1.Text = "username=" + username;
            label2.Text = "Filename=" + Filename;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            ServiceReference1.ConvertFiletoPdfSoapClient xx = new ServiceReference1.ConvertFiletoPdfSoapClient();
            //Query Convert Queue

            LoginUserConvertpdfQueueBLL ConpdfQueueBLL = new LoginUserConvertpdfQueueBLL();
            DataSet ds = ConpdfQueueBLL.Get_File();
            if (ds.Tables[0].Rows.Count > 0)
            {

                string username = ds.Tables[0].Rows[0][1].ToString();
                string Filename = ds.Tables[0].Rows[0][3].ToString();
                int id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());

                FileInfo file1 = new FileInfo(Filename);

                string storefolder = @"d:\" + "File_Convertpdf" + @"\" + "user" + @"\" +
                   username + @"\";
                string storeuploadFile = storefolder + "upload" + @"\";
                string storedownFile = storefolder + "Download" + @"\";

                string sourcefile = storeuploadFile + Filename;
                string outputfile = storedownFile + Filename.Replace(".xlsx", ".pdf");

                ConpdfQueueBLL.Delete_LoginUserConvertpdfQueue(id);

                xx.str(sourcefile, outputfile);
                xx.Close();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }
}
